package com.quasar.hpatient.dialog;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.TextView;

import com.quasar.hpatient.R;

import java.util.List;

import lib.quasar.base.dialog.BaseDialog;
import lib.quasar.widget.wheel.WheelView;

public class RadioThreeDialog extends BaseDialog {

    /******************************************************************************************/

    private OnDialogChangeListener listener;

    public RadioThreeDialog(Activity activity) {
        super(activity);
    }

    @Override
    protected int initView() {
        return R.layout.layout_dialog_radio_three;
    }

    @Override
    protected void initData() {

        final WheelView wheel1 = findViewById(R.id.dialog_radio_three_wheel1);
        final WheelView wheel2 = findViewById(R.id.dialog_radio_three_wheel2);
        final WheelView wheel3 = findViewById(R.id.dialog_radio_three_wheel3);
        wheel1.setOnWheelChangeListener((index, str) -> {
            if (null != listener) {
                listener.onChange(str, null, null, true);
            }
        });
        wheel2.setOnWheelChangeListener((index, str) -> {
            if (null != listener) {
                listener.onChange(null, str, null, true);
            }
        });
        wheel3.setOnWheelChangeListener((index, str) -> {
            if (null != listener) {
                listener.onChange(null, null, str, true);
            }
        });

        findViewById(R.id.dialog_radio_three_back).setOnClickListener(v -> dismiss());
        findViewById(R.id.dialog_radio_three_ok).setOnClickListener(v -> {

            if (null != listener) {
                final String text1 = wheel1.getCurText();
                final String text2 = wheel2.getCurText();
                final String text3 = wheel3.getCurText();
                listener.onChange(text1, text2, text3, false);
            }

            cancel();
        });
    }

    public void setList(List<String> list1, List<String> list2, List<String> list3) {


        if (null != list1 && list1.size() > 0) {
            final WheelView wheel1 = findViewById(R.id.dialog_radio_three_wheel1);
            wheel1.setList(list1);
        }

        if (null != list2 && list2.size() > 0) {
            final WheelView wheel2 = findViewById(R.id.dialog_radio_three_wheel2);
            wheel2.setList(list2);
        }

        if (null != list3 && list3.size() > 0) {
            final WheelView wheel3 = findViewById(R.id.dialog_radio_three_wheel3);
            wheel3.setList(list3);
        }
    }

    public void setTitle(String str) {

        if (TextUtils.isEmpty(str)) return;

        TextView text = findViewById(R.id.dialog_radio_three_title);
        if (null != text) {
            text.setText(str);
        }
    }

    public void setOnDialogChangeListener(OnDialogChangeListener mListener) {
        this.listener = mListener;
    }

    public interface OnDialogChangeListener {

        void onChange(String str1, String str2, String str3, boolean iswheel);
    }
}
